package cn.yj.core.business.controller;

import cn.yj.cgs.dba.entity.PartTimeJob;
import cn.yj.cgs.dba.entity.vo.PartTimeJobVo;
import cn.yj.common.Enums;
import cn.yj.syslog.common.LogType;
import cn.yj.syslog.common.OperateLog;
import cn.yj.config.annotation.Anonymous;
import cn.yj.config.web.AppBaseController;
import cn.yj.core.business.service.iservice.IPartTimeJob;
import cn.yj.entity.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author 永健
 * @since 2021-09-28 11:52
 */
@RestController
@RequestMapping("/partTimeJob")
public class PartTimeJobController extends AppBaseController<PartTimeJobVo> {

    @Resource
    IPartTimeJob iPartTimeJob;

    @Anonymous
    @GetMapping("/pageList")
    public R pageList(@RequestParam Map<String, Object> params) {
        params.put("deleted", Enums.Common.ZERO);
        return success(iPartTimeJob.pageList(params, page()));
    }


    @GetMapping("/myPublish")
    public R myPublish(@RequestParam Map<String, Object> params) {
        params.put("user_code", getUserCode());
        return success(iPartTimeJob.myPushPageList(params, page()));
    }


    @PostMapping("/save")
    @OperateLog(describe = "兼职信息发布",type = LogType.INSERT)
    public R publish(@RequestBody PartTimeJob partTimeJob) {
        partTimeJob.setUserCode(getUserCode());
        return iPartTimeJob.saveInfo(partTimeJob);
    }

    @PostMapping("/update")
    @OperateLog(describe = "兼职信息修改",type = LogType.UPDATE)
    public R updateInfo(@RequestBody PartTimeJob partTimeJob) {
        partTimeJob.setUserCode(getUserCode());
        return iPartTimeJob.updateInfoById(partTimeJob);
    }

    @Anonymous
    @GetMapping("/detail/{jobCode}")
    public R detail(@PathVariable String jobCode) {
        return success(iPartTimeJob.detailByCode(jobCode));
    }

    @DeleteMapping("/deleteInfoByCode/{jobCode}")
    @OperateLog(describe = "兼职信息删除",type = LogType.DELETE)
    public R deleteInfoByCode(@PathVariable String jobCode) {
        return result(iPartTimeJob.deleteInfoByCode(jobCode));
    }


}
